package mmc.server.shell.ops.function;

import mmc.server.shell.ShellException;
import mmc.server.shell.ops.Function;
import mmc.server.shell.ops.Operation;

public class AVG extends Function {

    public AVG(String text) throws ShellException {
        super(text, "avg", 2, true);
    }

    @Override
    public double execute() {
        double sum = 0;

        for (Operation o : arguments.getArguments()) {
            sum += o.execute();
        }

        return sum / arguments.getArguments().size();
    }
    
    public static String getDescription(){
    	return formatHelpString("avg(...)","compute average");
    }
}
